<!--
 * @Author: your name
 * @Date: 2020-05-28 21:05:48
 * @LastEditTime: 2020-05-28 23:10:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \source\pages\code\dictionary\components\edit.vue
--> 
<template>
  <Form ref="form" :model="entity" :rules="rules" :label-width="100">
    <Row class="rowTitle100">
      <FormItem label="类别" prop="typeId">
        <RadioGroup v-model="entity.typeId">
          <Radio :label="0" >系统</Radio>
          <Radio :label="1" >分类</Radio>
          <Radio :label="2" >字典</Radio>
          <Radio :label="3" >字典项</Radio>
        </RadioGroup>
      </FormItem>
    </Row>
    <Row class="rowTitle100">
      <FormItem label="名称" prop="name">
        <Input v-model="entity.name">
          <ColorPicker v-model="entity.color" slot="prepend" transfer size="small" transfer recommend />
        </Input>
      </FormItem>
    </Row>
    <Row class="rowTitle100">
      <FormItem label="编码" prop="code">
        <Input v-model="entity.code" />
      </FormItem>
    </Row>
    <Row class="rowTitle100">
      <FormItem label="图标" prop="icon">        
         <InputIcon v-model="entity.icon"></InputIcon>
      </FormItem>
    </Row>
    <FormItem label="状态" prop="status">    
       <dictionary code="system.dictionary.status"  v-model="entity.status" type="radio"/>
    </FormItem>
    <FormItem label="锁定" prop="number">     
       <dictionary code="system.dictionary.isStatic" v-model="entity.isStatic"  type="radio"/>
    </FormItem>
    <Row class="rowTitle100">
      <FormItem label="描述" prop="description">
        <Input v-model="entity.description" type="textarea" :rows="3"></Input>
      </FormItem>
    </Row>
    <FormItem>
      <Button type="primary" @click="handleSubmit">保存</Button>
      <Button @click="handleClose" class="ml20">取消</Button>
    </FormItem>
  </Form>
</template>
<script>
export default {
  name: 'Edit',
  data() {
    return {
      entity: this.v,
      rules: {
        name: [{ required: true, message: '必填', trigger: 'blur' }],
        code: [{ required: true, message: '必填', trigger: 'blur' }]
      }
    }
  },
  props: {
    v: Object
  },
  methods: {
    handleSubmit() {
      this.$refs.form.validate((v) => {
        if (v) {
          var url2 = `/api/Dictionary/update`
          this.$api.post(url2,  this.entity).then((r) => {
            if (r.success) {
              this.$Message.success('保存成功')
              this.$emit('on-ok')
            }
          })
        }
      })
    },
    handleClose() {
      this.$emit('on-close')
    }
  },
  watch: {
    v(v) {
      this.entity = this.v
      console.info(this.entity)
    }
  }
}
</script>
